import main from '../../../main';
import { download } from '../../../api';
import { clearEmptyKey } from '../../../utils/utils';
import { CardDetailWalletRefundApply,CardDetailWalletRefundReason} from './types';

// 列表
export async function apiGetCardDetailWalletRefundApplyList(pageNum: number, pageSize: number, params?: any) {
  let tParams = params ? clearEmptyKey(params) : null;
  let res = await main.api.get('/card/cardDetailWalletRefundApply/list', { params: { pageNum, pageSize, ...tParams } });

  return res;
}
// 详情
export async function apiGetcardDetailWalletRefundApplyDetail(cardDetailWalletRefundApplyDetailId: string) {
  let res = await main.api.get(`/card/cardDetailWalletRefundApply/${cardDetailWalletRefundApplyDetailId}`);

  return res;
}
// 列表
export async function apiGetCardDetailWalletRefundReason(params?: any) {
  let res = await main.api.get('/card/cardDetailWalletRefundReason/list', { params });

  return res;
}
// 列表
export async function apiGetPayCouponCardUserList(pageNum: number, pageSize: number, params?: any) {
  let tParams = params ? clearEmptyKey(params) : null;
  let res = await main.api.get('/card/payCouponCardUser/list', { params: { pageNum, pageSize, ...tParams } });

  return res;
}
// 列表
export async function apiGetCardPackOrderDetailList(pageNum: number, pageSize: number, params?: any) {
  let tParams = params ? clearEmptyKey(params) : null;
  let res = await main.api.get('/card/cardPackOrderDetail/list', { params: { pageNum, pageSize, ...tParams } });

  return res;
}
// 列表
export async function apiGetCardDetailWalletLogList(pageNum: number, pageSize: number, params?: any) {
  let tParams = params ? clearEmptyKey(params) : null;
  let res = await main.api.get('/card/cardDetailWalletLog/list', { params: { pageNum, pageSize, ...tParams } });

  return res;
}
// 更新
export async function apiUpdateCardDetailWalletRefundReasonDetail(
  cardDetailWalletRefundReasonId: string,
  data: CardDetailWalletRefundReason
) {
  let fn = cardDetailWalletRefundReasonId === 'create' ? main.api.post : main.api.put;
  let res = await fn(`/card/cardDetailWalletRefundReason`, data);

  return res;
}
export async function apiCardDetailWalletRefundReason(id: string) {
  
  let res = await main.api.get(`/card/cardDetailWalletRefundReason/${id}`, {});

  return res;
}
// 获取卡片退款信息
export async function apiGetRefundInfoByCardId(cardId: string | number) {
  let res = await main.api.get(`/card/cardDetailWalletRefundApply/getRefundInfoByCardId`, { params: { cardId } });
  return res;
}

// 修改
export async function apiUpdateCardDetailWalletRefundApplyDetail(data: CardDetailWalletRefundApply) {
  let res = await main.api.put(`/card/cardDetailWalletRefundApply`, data);

  return res;
}
// 提交退余额申请 || 创建
export async function apiCardDetailWalletRefundApplyDetail(data: CardDetailWalletRefundApply) {
  let res = await main.api.post(`/card/cardDetailWalletRefundApply`, data);

  return res;
}

// 审核退余额申请
export async function apicardDetailWalletRefundApplyEditAudit(data: CardDetailWalletRefundApply) {
  let res = await main.api.post('/card/cardDetailWalletRefundApply/editAudit', data);

  return res;
}

// 退款 退余额申请
export async function apicardDetailWalletRefundApplyEditStatus(data: CardDetailWalletRefundApply) {
  let res = await main.api.post('/card/cardDetailWalletRefundApply/editStatus', data);

  return res;
}
// 系统异常 重新提交打款方式
export async function apicardDetailWalletRefundSysErrorUpdateReviceType(data: CardDetailWalletRefundApply) {
  let res = await main.api.post('/card/cardDetailWalletRefundApply/editResourceBackup', data);

  return res;
}

// 删除
export async function apiDeleteCardDetailWalletRefundApplyDetail(cardDetailWalletRefundApplyId: string) {
  let res = await main.api.delete(`/card/cardDetailWalletRefundApply/${cardDetailWalletRefundApplyId}`);

  return res;
}

// 导出
export async function apiExportCardDetailWalletRefundApply(params: any) {
  let res = await main.api.get('/card/cardDetailWalletRefundApply/export', { params });
  return res;
}
// 获取申请记录操作日志
export async function apiGetCardOperationLog(type: string, cardDetailWalletRefundApplyId: number) {
  let res = await main.api.get(`/card/cardOperationLog/list`, {
    params: {
      orderByColumn: 'createTime',
      isAsc: 'desc',
      logType: type,
      businessId: cardDetailWalletRefundApplyId,
    },
  });

  return res;
}

// 批量审核 模板下载
export async function apiBatchEditStatusTaskTemplate() {
  await download('/card/cardImport/general/editStatus', {}, `批量审核退款模板_${new Date().getTime()}.xlsx`);
}
// 批量审核 导入
export async function apiBatchEditStatusTask(exportName: string, url: string) {
  return await main.api.get('/card/cardDetailWalletRefundApply/batchEditStatusTask', { params: { exportName, url } });
}

// 批量退款 使用ID
export async function apiBatchRefund(ids: string) {
  return await main.api.post('/card/cardDetailWalletRefundApply/batchRefund', { ids });
}
// 批量退款汇总 使用ID
export async function apiBatchRefundSum(ids: string) {
  return await main.api.post('/card/cardDetailWalletRefundApply/batchSummary', { ids });
}

// 批量修改状态为打款成功
export async function apiBatchUpateStatusSuccess(ids: string[]) {
  return await main.api.post('/card/cardDetailWalletRefundApply/batchSuccess', ids);
}
// 支付宝打款
export async function apiPayAlipay(
  orderRefundId: string,
  refundAmount: string | number,
  transferAccountPassword: string
) {
  return await main.api.post('/card/cardDetailWalletRefundApply/transferAccount', {
    orderRefundId,
    refundAmount,
    transferAccountPassword,
  });
}

// 加急
export async function apiCardDetailWalletRefundApplyEditTag(data: CardDetailWalletRefundApply) {
  let res = await main.api.put(`/card/cardDetailWalletRefundApply/editTag`, data);

  return res;
}

/**
 * 获取退款申请客户端退款状态
 */
export async function apiGetRefundApplyDetail(id?: string | number) {
  var res = await main.api.get(`/card/cardDetailWalletRefundApply/getClientStatus`, { params: { id } });
  return res;
}
